package com.testmanager.testmananger.shuiyou.common.web;

import com.alibaba.fastjson.JSONObject;
import com.testmanager.testmananger.shuiyou.common.service.OtherDbOperaService;
import com.testmanager.testmananger.shuiyou.szjk.dto.ChangeExpressionDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@Slf4j
@RequestMapping("/shuiyou/common")
public class OtherDbOperateResource {

    @Autowired
    OtherDbOperaService otherDbOperaService;
    /**
     * 1.根据指标id查询指标详细信息 前置信息 指标信息 对应指标元
     * 2.修改数据库值 （局端oracle，云端mysql）
     * 3.修改redis中数据
     * 4.新增数据库值
     *
     */



    @GetMapping("getRuleInfo/{sqlenv}/{ruleid}")
    public ResponseEntity getRuleInfo(@PathVariable("ruleid")String ruleid,@PathVariable("sqlenv") int sqlenv){
        return otherDbOperaService.getRuleInfo(ruleid,sqlenv);
    }

    @GetMapping("getsqlenvs")
    public ResponseEntity getSqlEnv(){
        return  ResponseEntity.ok(otherDbOperaService.getSqlEnvs());
    }

    @GetMapping("getRedisFile/{nsrid}")
    public ResponseEntity getRedisContent(@PathVariable("nsrid") String nsrid){
        log.info("visit:getRedisContent");
        return otherDbOperaService.getRedisFile(nsrid);
    }

    @PostMapping("updataRedisContent/{nsrid}")
    public ResponseEntity updateRedisContent(@RequestBody JSONObject json, @PathVariable("nsrid") String nsrid){
        log.info("visit:updataRedisContent/{},json:{}",nsrid,json);

        return otherDbOperaService.updateRedisContent(nsrid,json);
    }
    @GetMapping("getRuleResult/{nsrid}/{ruleid}")
    public ResponseEntity getRuleResult(@PathVariable("nsrid")String nsrid,@PathVariable("ruleid")String ruleid){
        log.info("visit:getRuleResult/{}/{}",nsrid,ruleid);

        return otherDbOperaService.getRuleResult(ruleid,nsrid);
    }


}
